package cz.cuni.amis.episodic.bayes.utils;

import java.util.Collections;
import java.util.List;

import com.itextpdf.text.pdf.PdfStructTreeController.returnType;

public class DyBaNeMUtil {

	/**
	 * Returns name of variable corresponding to the given level of hierarchy.
	 * 
	 * @param depth
	 * @return
	 */
	public static String getNodeNameForDepth(int depth) {
		if (depth == 0) {
			return "O";
		} else {
			return "G" + depth;
		}
	}
	
	public static int getDepthForNodeName(String nodeName) {
		if(nodeName.equals("O")) return 0;
		if(nodeName.startsWith("G")) return Integer.parseInt(nodeName.substring(1));
		// otherwise it is error
		return -1;
	}

	/**
	 * Returns sublist given by the two indexes in range array.
	 * @param list
	 * @param range
	 * @return
	 */
	public static <T> List<T> subList(List<T> list, int[] range) {
		if (list.size() <= range[0])
			return Collections.emptyList();
		if (list.size() < range[1])
			return list.subList(range[0], list.size());
		else
			return list.subList(range[0], range[1]);
	}

}
